<!-- Author: Moe Kyaw THu Aung --> 
<!-- Last Modified: 11 Sep 2012 --> 
<?php
	session_start();
	include("confs/startOrder.php");
	include("confs/config.php");
	
	if(count($_SESSION['cart']) < 1) {
		header("location: shopping.php");
		exit(0);
	}
	
	$conn = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD);
	mysql_select_db($DB_NAME, $conn);
?>
<html>
	<head>
		<title>My Book Store : Ordering</title>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/jquery.validate.js"></script>
		<script type="text/javascript">
		
			$(document).ready(function() {
				$("form").validate({
					rules: {
						name: {
							required: true,
							minlength: 4
						},
						email: {
							required: true,
							email: true
						},
						phone: {
							required: true,
							digits: true,
							minlength: 8
						},
						address: {
							required: true,
							minlength: 4
						},
						terms: {
							required: true,
						},
					}
				});
			});
		</script>
	</head>
	<body>
		<div id="wrapper">
			<div id="head">
				<h1>My Book Store : Ordering</h1>
			</div>
			
			<div id="content">
			
				<div id="order-form">
					<h4>Please fill this form to complete your order.</h4>
					<form name="formOne" action="actions.php?do=order" method="post">
						<table>
                       
							<tr>
								<td valign='top'>Name</td>
								<td><input type="text" name="name" value="<?php echo $name; ?>"/></td>
							</tr>
							<tr>
								<td valign='top'>Email</td>
								<td><input type="text" name="email" value="<?php echo $email; ?>"/></td>
							</tr>
							<tr>
								<td valign='top'>Phone</td>
								<td><input type="text" id="phone" name="phone" onChange="phonevalidate()"/> </td>
							</tr>
                            <tr>
                            <td><label style="color: #F00;" id="errorPhone"></label>
                            </td>
                            </tr>
							<tr>
								<td valign='top'>Address</td>
								<td><input type="text" name="address" /></td>
							</tr>
                            <tr>
								<td width="auto"><input type="checkbox" name="terms"/></td><td>I have read and accept the <a href="#">terms &amp; conditions</a></td>
							</tr>
							<tr>
								<td></td>
								<td>
									<input type="submit" name="signup" value="Order Now &raquo;" />
									&nbsp; <a href="shopping.php">Continue Shopping</a>
								</td>
							</tr>
						</table>
					</form>
				</div>
				
				<div id="cart-content">
					<table id="view-cart" cellspacing="1" cellpadding="8">
				
						<tr>
							<th class='action'></th>
							<th>Price</th>
							<th>Quantity</th>
							<th>Sub-Total</th>
							<th class='action'></th>
						</tr>
                        <?php error_reporting (E_ALL ^ E_NOTICE); ?>
				
					<?php
						foreach($_SESSION['cart'] as $id => $qty) {
							$result = mysql_query("SELECT * FROM items WHERE id = $id");
							$row = mysql_fetch_assoc($result);
							$id = $row['id'];
						
							echo "<tr>";
							echo "<td width='250px'><b>" . $row['name'] . "</b></td>";
							echo "<td>$" . $row['price'] . "</td>";
							echo "<td align='center'>$qty</td>";
							echo "<td>\$" . ($row['price'] * $qty) . "</td>";
							echo "</tr>";
						
							$total += ($row['price'] * $qty);
						}
					
						echo "<tr>";
						echo "<th align='right' colspan='3' style='padding:10px;'>Total :</th>";
						echo "<td><b>\$$total</b></td>";
						echo "</tr>";
					?>
				
					</table>
					</form>
				
				</div>
				
			</div>
			
			<br /><br />
			
			<div id="foot">
				&copy; OneStop JCU.
			</div>
		</div>
	</body>
</html>